import 'dart:convert';
import 'package:ffmpeg_kit_flutter_new/chapter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:dio/dio.dart' as dio;
import 'package:smart_translator/app/db/DbDAOHelper.dart';
import 'package:smart_translator/app/event/DataCallBack.dart';
import 'package:smart_translator/app/modules/home/controllers/home_controller.dart';
import 'package:smart_translator/app/views/controller/IndexViewController.dart';
import '../../../const/AppConst.dart';
import '../../../db/database.dart';
import '../../../routes/app_pages.dart';
import '../../../services/AudioService.dart';
import '../../../style/widget_style.dart';
import '../../../utils/tips.dart';
import '../../IndexTranslation/controllers/index_translation_controller.dart';

class SearchingtranscriptController extends GetxController {

  RxList<Session> sessionList = RxList<Session>();

  @override
  void onInit() {
    super.onInit();

  }

  @override
  void onReady() {
    super.onReady();

  }

  @override
  void onClose() {
    super.onClose();
  }

  void searchingContent(String searchContent) {
    getSessionCollectionsByKeyWord(searchContent);

  }

  void getSessionCollectionsByKeyWord(String searchContent) {
    sessionList.clear();
    if (searchContent.trim() == '') {
       return;
    }

    //搜索session name字段.
    DbDAOHelper().obtainAllSession().then((sessions) {
      sessions.forEach((item) {
         if(item.session_name.contains(searchContent)) {
           sessionList.add(item);
         }
      });
    });

    //搜索转写脚本字段
    DbDAOHelper().obtainAudioTranscriptByKeyWord(searchContent).then((audioScripts){
      audioScripts.forEach((audioScriptItem) {
        DbDAOHelper().obtainSessionBySessionId(audioScriptItem.session_id).then((sessionCollection) {
          sessionCollection.forEach((sessionItem) {
            sessionList.add(sessionItem);
          });
        });
      });
    });

  }


}
